<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\Http\Controllers\Controller;

use DB;

class IndexController extends Controller
{
    // 首页
    public function index()
    {
   		//分配轮播数据
        $list = DB::table('storecarousel')->get();
   		
        //网站配置
        $con = DB::table('storeconfig')->where('configStatus','0')->first();

        //首页商品分类
        $cdata = DB::table('goodscate')
            ->whereStatusAndPath(1,'0')
            ->get();

        // 查找goodscate表中状态为1并且cid不为0的字段
        $cdatas = DB::table('goodscate')->where([
                ['status', '=', '1'],
                ['cid', '<>', '0'],
            ])->get();
        // goodscate
       // 查找goodscate表中状态为1并且cid不为0的字段
        $ccdata = DB::table('goodscate')->where([
                ['status', '=', '1'],
                ['cid', '<>', '0'],
            ])->get();

        //商品遍历（goods,goodscate,goodsmain）
        $goods = DB::table('goods')
            ->join('goodscate', 'goodscate.id', '=', 'goods.cid')
            ->join('goodsmain', 'goodsmain.gid', '=', 'goods.id')
            ->select('goods.name','goods.status','goods.cid','goods.biaoqian','goods.tuijian','goods.description','goodscate.id','goodscate.status','goodscate.images','goodsmain.gid','goodsmain.title','goodsmain.hwprice','goodsmain.price','goodsmain.status','goodsmain.pic0','goods.id as goodsid')
            ->where([
                ['goods.status', '=', '1'],
                ['goodscate.status', '=', '1'],
                ['goodsmain.status', '=', '1'],
            ])->get();
        
        // 查找分类表和商品表
        $gcdatas = DB::table('goodscate')->where('status', '1')->get();
        $goodsId = DB::table('goods')->where('status', '1')->get();
        // dd($goods);
        // dd($gcdatas);
        // dd($cdata);
        // dd($gcdatas);
   		return view('home.index',['l' => $list,'cdata' => $cdata,'cdatas' => $cdatas,'ccdata' => $ccdata,'goods' => $goods,'gcdatas' => $gcdatas,'goodsId' => $goodsId]);
      
    }

}
